#include <stdio.h>
#include <stdlib.h>

typedef struct
{
    int *arr;
    int size;
} Result;

Result getsum(int *num, int numsize, int target)
{
    for (int i = 0; i < numsize - 1; ++i)
    {
        for (int j = i + 1; j < numsize; ++j)
        {
            if (num[i] + num[j] == target)
            {
                int *result = (int *)malloc(2 * sizeof(int));
                result[0] = i;
                result[1] = j;
                Result res = {result, 2};
                return res;
            }
        }
    }
    Result res = {NULL, 0};
    return res;
}
int main(void)
{
    int num1[]={2, 7, 11, 15};
    int target1 = 9;
    Result res1 = getsum(num1, 4, target1);
    if (res1.arr != NULL)
    {
        printf("相应值的下标为: %d, %d\n", res1.arr[0], res1.arr[1]);
        free(res1.arr);
    }
    else
    {
        printf("没有找到答案.\n");
    }

    int num2[] = {3, 2, 4};
    int target2 = 6;
    Result res2 = getsum(num2, 3, target2);
    if (res2.arr != NULL)
    {
        printf("相应值的下标为: %d, %d\n", res2.arr[0], res2.arr[1]);
        free(res2.arr);
    }
    else
    {
        printf("没有找到答案.\n");
    }

    int num3[] = {3, 3};
    int target3 = 6;
    Result res3 = getsum(num3, 2, target3);
    if (res3.arr != NULL)
    {
        printf("相应值的下标为: %d, %d\n", res3.arr[0], res3.arr[1]);
        free(res3.arr);
    }
    else
    {
        printf("没有找到答案.\n");
    }

    return 0;
}